package com.focus.xyz.other.cases;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.common.webdriver.DriverFactory;
import com.focus.xyz.core.utils.ExcelUtils;
import com.focus.xyz.core.utils.ProcessUtil;
import com.focus.xyz.other.pages.njhrss.DataPage;
import org.apache.commons.lang.StringUtils;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.*;

/**
 * Created by chenmeng on 2016/5/3.
 */
public class ModifyDataTest {
    private WebDriver driver;
    public ExcelUtils eu;
    private DataPage dataPage;

    @Parameters({"nodeUrl","browser"})
    @BeforeClass(alwaysRun = true)
    public void setUp(String nodeUrl,String browser) throws Exception{
        driver = DriverFactory.getDriver(nodeUrl).getBrowser(browser);
        dataPage = new DataPage(driver,new Action(driver));
        dataPage.openPage();
        eu = new ExcelUtils("F:\\njhrss.xlsx");
    }

    @AfterClass(alwaysRun = true)
    public void tearDown(){
        if(driver!=null){
            driver.close();
            driver.quit();
        }
        if(ProcessUtil.findProcess("iexplore.exe")){
            ProcessUtil.killProcess("iexplore.exe");
        }
    }

    /*@Test
    public void export() throws Exception{
        DataPage dataPage = new DataPage(driver,new PageAction(driver));
        dataPage.openPage();
        dataPage.query();
        dataPage.export();
    }*/

    @DataProvider(name = "getData1")
    public Object[][] getData1() throws Exception{
        String[][] data = null;
        try {
            eu.setSelectedSheetName("Data1");
            eu.setOnlyReadOneSheet(true);
            eu.setStartReadPos(1);
            data = eu.readExcelArray();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;
    }

    @DataProvider(name = "getData2")
    public Object[][] getData2() throws Exception{
        String[][] data = null;
        try {
            eu.setSelectedSheetName("Data2");
            eu.setOnlyReadOneSheet(true);
            eu.setStartReadPos(1);
            data = eu.readExcelArray();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;
    }

    @Test(dataProvider = "getData1")
    public void modifyData1(String id,String tym,String spm,String bzlx,String zflb,String rate,String cansell,String desc) throws Exception{
        if(StringUtils.isNotBlank(zflb)){
            if("乙类".equals(zflb.trim())){
                if(StringUtils.isBlank(rate)){
                    //搜索查询
                    dataPage.qryByCond(spm);
                    dataPage.modify(eu,id,tym,spm,bzlx);
                }

            }else{
                // 甲类，丙类
                if(StringUtils.isBlank(rate)||StringUtils.isBlank(cansell)){
//                if(StringUtils.isBlank(rate)){
                    //搜索查询
                    dataPage.qryByCond(spm);
                    dataPage.modify(eu,id,tym,spm,bzlx);
                }
            }
        }else{
            //更新 标注剂型；支付类别；医保支付比例；药店可否出售；备注
            dataPage.qryByCond(spm);
            dataPage.modify1(eu,id,tym,spm);
        }
    }

  /*  @Test(dataProvider = "getData1")
    public void modifyData2(String id,String tym,String spm,String bzlx,String zflb,String rate,String cansell,String desc) throws Exception{

    }*/
}
